package vista;

import java.awt.BorderLayout;
import java.awt.Color;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import javax.swing.WindowConstants;
import javax.swing.table.AbstractTableModel;
import modelo.ModeloIngredientes;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class VistaReportes extends javax.swing.JFrame {
	
	private JScrollPane jScrollPane1;
	private JPanel jPanel1;
	private JTable Tabla;
	ResultSet rs=null;
	Vector<ModeloIngredientes> vIng=new Vector<ModeloIngredientes>();
	int tipo;
	
	
	public void setResultados(AbstractTableModel abstractTableModel) {
		
		Tabla.setModel(abstractTableModel);		
	}
	
	
	public VistaReportes(java.sql.ResultSet rs, Vector<ModeloIngredientes> vIng, int tipo)
	{
		super();
		this.rs=rs;
		this.vIng=vIng;
		this.tipo=tipo;
		initGUI();
	}
	
	public VistaReportes(int tipo)
	{
		super();
		this.tipo=tipo;
		initGUI();
	}
	
	public VistaReportes()
	{
		super();
		initGUI();
	}
	
	
	//private void initGUI(java.sql.ResultSet rs, Vector<ModeloIngredientes> vIng, int tipo) {
	private void initGUI() {
	
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{				
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setLayout(null);
				jPanel1.setBackground(new java.awt.Color(255,255,255));

				jScrollPane1 = new JScrollPane();
				jPanel1.add(jScrollPane1);
				jScrollPane1.setBounds(12, 12, 754, 338);
				{
					Tabla = new JTable();
					jScrollPane1.setViewportView(Tabla);
					
					Tabla.setForeground(Color.white);
					//Tabla.setBackground(Color.WHITE);
					Tabla.setBackground(new java.awt.Color(49,120,189));
					
					
				}
				
				
			}
			this.setLocationRelativeTo(null);
			this.setVisible(true);

			pack();
			setSize(800, 400);
			
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
		
	}
	
	
	public void listados(java.sql.ResultSet rs, Vector<ModeloIngredientes> vIng, int tipo) throws SQLException
	{
			
		if (tipo == 0)//por cedula
		{							
			
//			Tabla = new JTable(50,3);
//			jPanel1.add(Tabla);
					
			
			int i=0;
			
			while(rs.next())
			{						
				Tabla.setValueAt(rs.getString("id_orden"), i, 0);
				Tabla.setValueAt(rs.getString("id_producto"), i, 1);
				Tabla.setValueAt(Integer.toString(rs.getInt("can")), i, 2);
				//Tabla.setValueAt(Integer.toString(rs.getInt("cantidad")), i, 3);
				i++;
				this.setTitle("Ordenes:        Orden	       	Producto		    Cantidad parcial");
				
//				Tabla.setForeground(Color.green);
//				Tabla.setBackground(Color.YELLOW.blue);
			}
			
//		
		}
//		
		else if (tipo == 1)
		{
			//Tabla = new JTable(vIng.size(),4);
			//jPanel1.add(Tabla);
			
			for(int i = 0; i<vIng.size(); i++)
			{						
				Tabla.setValueAt(vIng.elementAt(i).getId(), i, 0);
				Tabla.setValueAt(vIng.elementAt(i).getDescripcion(), i, 1);
				Tabla.setValueAt(vIng.elementAt(i).getCosto(), i, 2);
				Tabla.setValueAt(vIng.elementAt(i).getStock(), i, 3);
			
				this.setTitle("INGREDIENTES:    Codigo		Descripcion		Costo   	Stock ");
				
//				Tabla.setForeground(Color.green);
//				Tabla.setBackground(Color.YELLOW.blue);
			}
		}	
			
		else if (tipo == 2)
			
			{					
							
				//Tabla = new JTable(50,3);
				//jPanel1.add(Tabla);
				
				int i=0;
				
				while(rs.next())
				{						
					Tabla.setValueAt(rs.getString("producto"), i, 0);
					Tabla.setValueAt(Integer.toString(rs.getInt("cantidad")), i, 1);
					Tabla.setValueAt(rs.getString("ingrediente"), i, 2);
					//Tabla.setValueAt(Integer.toString(rs.getInt("cantidad")), i, 3);
					i++;
					this.setTitle("Ingredientes mas utilizados:        Producto		    Cantidad             Ingrediente");
					
//					Tabla.setForeground(Color.green);
//					Tabla.setBackground(Color.YELLOW.blue);
				}
				
//			
			}
			
		Tabla.setBounds(0, 0, 784, 362);		
		JScrollPane jScrollPane = new JScrollPane(Tabla);
		this.add(jScrollPane);
		jScrollPane.setPreferredSize(new java.awt.Dimension(784, 362));
	}
	
	

}
